t=int(input())

for _ in range(t):

    n=int(input())
    a=[]
    for i in range(n):
        t,d,l=map(int,input().split())
        a.append((t,d,l))
    a.sort(key=lambda x: (x[0],x[1]))
